import {Component, OnDestroy, OnInit} from "@angular/core";
import {sjgzxinModuledatas} from "../pubcomponent/pageTitle.datas";
import {FormBuilder, FormGroup} from "@angular/forms";
import {MyValidator} from "../myvalidator-util";
import {CommService} from "../comm-service";
import {MyhttpService} from "../myhttp.service";
import {Router} from "@angular/router";
import {LocalStorageService} from "../local-storage-service";

declare var $: any;
declare var AMap: any;

@Component({
  template: `
    <div *ngIf="pagetitleobj">
      <page-title [o]="pagetitleobj"></page-title>
    </div>
    <div class="portlet box blue">
      <div class="portlet-title">
        <div class="caption">
          试卷运送计划
        </div>
      </div>
      <div class="portlet-body">
        <div class="row">
          <form class="form-horizontal" role="form" [formGroup]="formgroup_yyjh">
            <div class="col-lg-4">
              <div class="form-group">
                <label class="control-label col-lg-3">
                  <require-label></require-label>
                  计划名称：
                </label>
                <div class="col-lg-8">
                  <input type="text" class="form-control" formControlName="ysjhmcCtr"/>
                  <div
                    *ngIf="formgroup_yyjh.get('ysjhmcCtr').invalid&&formgroup_yyjh.get('ysjhmcCtr').dirty">
                          <span *ngIf="formgroup_yyjh.hasError('myrequire','ysjhmcCtr')">
                                <tool-tip [o]="formgroup_yyjh.getError('myrequire','ysjhmcCtr').msg"></tool-tip>
                          </span>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-lg-7">
              <div class="form-group">
                <label class="col-lg-2 control-label">
                  <require-label></require-label>
                  计划时间：
                </label>
                <div class="col-lg-10">
                  <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-calculator"></i></span>
                    <input type="text" class="form-control datetimepickerB_content" id="s_btimeID">
                    <span class="input-group-addon">至</span>
                    <input type="text" class="form-control datetimepickerE_content" id="s_etimeID">
                    <span class="input-group-addon"><i class="fa fa-calculator"></i></span>
                  </div>
                  <div *ngIf="noReactiveFormField.yyjhsjwarnflag">
                    <tool-tip [o]="noReactiveFormField.yyjhsjwarntext"></tool-tip>
                  </div>
                </div>
              </div>
            </div>
          </form>
        </div>
        <div id="myCavans">
          <div [style.heigth]="canvasHeightstr">
            <div *ngFor="let item of pointerList;index as index" class="mynode" [attr.id]="item.pointerID"
                 [style.top]="item.top" [style.left]="item.left" (click)="pointerHander(item)">
              <div class="mynodelabel" [attr.title]="item.dzmc">{{item.dzjc}}
              </div>
            </div>
          </div>
          <ng-container *ngIf="lineList.length">
            <div *ngFor="let lineobj of lineList" class="line"
                 [ngStyle]="{'left':lineobj.left,'top':lineobj.top,'width':lineobj.width,'transform':lineobj.transform}"
                 [attr.id]="lineobj.lineID">
              <div class="linebtn" *ngIf="!lineobj.rwxx" title="配置任务信息" [style.left]="lineobj.linebtn_left"
                   (click)="pzrwxx('add',lineobj)">
                <i class="fa fa-pencil"></i>
              </div>
              <div class="linebtn active" *ngIf="lineobj.rwxx" title="修改任务信息" [style.left]="lineobj.linebtn_left"
                   (click)="pzrwxx('edite',lineobj)">
                <i class="fa fa-pencil"></i>
              </div>
              <div *ngIf="lineobj.ismpointer" class="linebtn" title="添加中间环节"
                   [style.left]="lineobj.linebtn1_left" (click)="addPointer(lineobj)">
                <i class="fa fa-share-alt"></i>
              </div>
            </div>
          </ng-container>
        </div>
        <div class="row">
          <div class="col-lg-12 text-right">
            <button type="button" class="btn btn-default" (click)="actionDone(0)">取 消</button>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <button type="button" class="btn btn-primary" (click)="actionDone(1)">保 存</button>
          </div>
        </div>


        <div class="modal fad" id="add_pointerModal" tabindex="-1" role="dialog"
             aria-labelledby="myModalLabel">
          <div class="modal-dialog smmodalwidth" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                  aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">中间环节个数</h4>
              </div>
              <div class="modal-body">
                <div class="row">
                  <form class="form-horizontal" role="form" [formGroup]="formgroup_addpointer">
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="control-label col-lg-3">
                          <require-label></require-label>
                          环节数:</label>
                        <div class="col-lg-8">
                          <input type="text" class="form-control" formControlName="numCtr"/>
                          <div
                            *ngIf="formgroup_addpointer.get('numCtr').invalid&&formgroup_addpointer.get('numCtr').dirty">
                          <span *ngIf="formgroup_addpointer.hasError('number','numCtr')">
                                <tool-tip [o]="formgroup_addpointer.getError('number','numCtr').msg"></tool-tip>
                          </span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </form>
                </div>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-primary" (click)="addsure_pointer()">确 定</button>
              </div>
            </div>
          </div>
        </div>

        <div class="modal fad" id="pz_pointermsgModal" tabindex="-1" role="dialog"
             aria-labelledby="myModalLabel">
          <div class="modal-dialog smmodalwidth" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                  aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">选择地址信息</h4>
              </div>
              <div class="modal-body">
                <div class="row">
                  <form class="form-horizontal" role="form" [formGroup]="formgroup_pointermsg">
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="control-label col-lg-3">
                          <require-label></require-label>
                          地址类型:</label>
                        <div class="col-lg-8">
                          <select class="form-control" id="dzlxSelect" name="dzlx" formControlName="dzlxCtr"
                                  (change)="dzlxChange()"></select>
                          <div
                            *ngIf="formgroup_pointermsg.get('dzlxCtr').invalid&&formgroup_pointermsg.get('dzlxCtr').dirty">
                          <span *ngIf="formgroup_pointermsg.hasError('snone','dzlxCtr')">
                                <tool-tip [o]="formgroup_pointermsg.getError('snone','dzlxCtr').msg"></tool-tip>
                          </span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </form>
                </div>
                <div class="row">
                  <div class="col-lg-12" *ngIf="table_bms">
                    <my-table [o]="table_bms" (outhander)="tableHander($event)"></my-table>
                  </div>
                </div>
                <div class="row">
                  <div class="col-lg-12" *ngIf="table_bzhkd">
                    <my-table [o]="table_bzhkd" (outhander)="tableHander($event)"></my-table>
                  </div>
                </div>
                <div class="row" id="dzform">
                  <form class="form-horizontal" role="form" [formGroup]="formgroup_dzform">
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="col-lg-3 control-label">
                          <require-label></require-label>
                          地址名称：
                        </label>
                        <div class="col-lg-8">
                          <input type="text" id="cfdmc" placeholder="地址名称" class="form-control"
                                 formControlName="dzmcCtr"/>
                          <div
                            *ngIf="formgroup_dzform.get('dzmcCtr').invalid&&formgroup_dzform.get('dzmcCtr').dirty">
                          <span *ngIf="formgroup_dzform.hasError('myrequire','dzmcCtr')">
                                <tool-tip [o]="formgroup_dzform.getError('myrequire','dzmcCtr').msg"></tool-tip>
                          </span>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="col-lg-3 control-label">
                          <require-label></require-label>
                          地址位置：
                        </label>
                        <div class="col-lg-7">
                          <input type="text" placeholder="地址位置" class="form-control" formControlName="dzCtr" readonly/>
                          <div
                            *ngIf="formgroup_dzform.get('dzCtr').invalid&&formgroup_dzform.get('dzCtr').dirty">
                          <span *ngIf="formgroup_dzform.hasError('myrequire','dzCtr')">
                                <tool-tip [o]="formgroup_dzform.getError('myrequire','dzCtr').msg"></tool-tip>
                          </span>
                          </div>
                        </div>
                        <div class="col-lg-2">
                          <!--<button type="button" class="btn  blue" [disabled]="formgroup_dzform.get('dzCtr').invalid"-->
                          <!--(click)="getJWD()">-->
                          <!--<i class="fa fa-paper-plane-o"></i> 地址-->
                          <!--</button>-->
                          <button type="button" class="btn  blue" (click)="getJWD()">
                            <i class="fa fa-paper-plane-o"></i> 地址
                          </button>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="col-lg-3 control-label">
                          <require-label></require-label>
                          地址经度：
                        </label>
                        <div class="col-lg-8">
                          <input type="text" class="form-control" formControlName="dzjdCtr" readonly/>
                          <div
                            *ngIf="formgroup_dzform.get('dzjdCtr').invalid&&formgroup_dzform.get('dzjdCtr').dirty">
                          <span *ngIf="formgroup_dzform.hasError('myrequire','dzjdCtr')">
                                <tool-tip [o]="formgroup_dzform.getError('myrequire','dzjdCtr').msg"></tool-tip>
                          </span>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="col-lg-3 control-label">
                          <require-label></require-label>
                          地址纬度：
                        </label>
                        <div class="col-lg-8">
                          <input type="text" class="form-control" formControlName="dzwdCtr" readonly/>
                          <div
                            *ngIf="formgroup_dzform.get('dzwdCtr').invalid&&formgroup_dzform.get('dzwdCtr').dirty">
                          <span *ngIf="formgroup_dzform.hasError('myrequire','dzwdCtr')">
                                <tool-tip [o]="formgroup_dzform.getError('myrequire','dzwdCtr').msg"></tool-tip>
                          </span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </form>
                </div>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-primary" (click)="addsure_pointerMsg()">确 定</button>
              </div>
            </div>
          </div>
        </div>

        <div class="modal fade bs-example-modal-lg" id="mymap" tabindex="-1" role="dialog"
             aria-labelledby="myModalLabel">
          <div class="modal-dialog bigmodalwidth" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                  aria-hidden="true">&times;</span></button>
                <h4>选择地址，填充经纬度</h4>
              </div>
              <div class="modal-body">
                <div class="row">
                  <div class="col-lg-12" style="position: relative;">
                    <div id="mapContainer"></div>
                    <div class="searchform">
                      <form class="form-horizontal" role="form">
                        <div class="form-group">
                          <label class="col-lg-3 control-label">地址：</label>
                          <div class="col-lg-9">
                            <input type="text" class="form-control" name="sdzcache"
                                   [(ngModel)]="noReactiveFormField.sdzcache" (keydown)="searchAddress($event)"/>
                          </div>
                        </div>
                      </form>
                      <div id="panellist"></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="modal fad" id="pz_rwxxModal" tabindex="-1" role="dialog"
             aria-labelledby="myModalLabel">
          <div class="modal-dialog smmodalwidth" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                  aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">{{modaltitle}}</h4>
              </div>
              <div class="modal-body">
                <div class="row">
                  <form class="form-horizontal" role="form" [formGroup]="formgroup_rwxx">
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="control-label col-lg-3">
                          <require-label></require-label>
                          任务类型:</label>
                        <div class="col-lg-8">
                          <select class="form-control" id="rwlxSelect" formControlName="rwlxmCtr"></select>
                          <div
                            *ngIf="formgroup_rwxx.get('rwlxmCtr').invalid&&formgroup_rwxx.get('rwlxmCtr').dirty">
                          <span *ngIf="formgroup_rwxx.hasError('snone','rwlxmCtr')">
                                <tool-tip [o]="formgroup_rwxx.getError('snone','rwlxmCtr').msg"></tool-tip>
                          </span>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="control-label col-lg-3">
                          <require-label></require-label>
                          任务名称
                        </label>
                        <div class="col-lg-8">
                          <input type="text" class="form-control" formControlName="ysrwmcCtr"/>
                          <div
                            *ngIf="formgroup_rwxx.get('ysrwmcCtr').invalid&&formgroup_rwxx.get('ysrwmcCtr').dirty">
                          <span *ngIf="formgroup_rwxx.hasError('myrequire','ysrwmcCtr')">
                                <tool-tip [o]="formgroup_rwxx.getError('myrequire','ysrwmcCtr').msg"></tool-tip>
                          </span>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="control-label col-lg-3">
                          <require-label></require-label>
                          开始时间：
                        </label>
                        <div class="col-lg-8">
                          <div class="input-group date date_btime">
                            <input type="text" id="kssj_rw" placeholder="" class="form-control" readonly/>
                            <span class="input-group-btn">
                  <button class="btn default date-set" type="button">
                  <i class="fa fa-calendar"></i>
                  </button>
                  </span>
                            <div *ngIf="noReactiveFormField.kssjwarnflag">
                              <tool-tip [o]="noReactiveFormField.ksskwarntext"></tool-tip>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="control-label col-lg-3">
                          <require-label></require-label>
                          结束时间：
                        </label>
                        <div class="col-lg-8">
                          <div class="input-group date date_etime">
                            <input type="text" id="jssj_rw" placeholder="" class="form-control" readonly/>
                            <span class="input-group-btn">
                  <button class="btn default date-set" type="button">
                  <i class="fa fa-calendar"></i>
                  </button>
                  </span>
                            <div *ngIf="noReactiveFormField.jssjwarnflag">
                              <tool-tip [o]="noReactiveFormField.jssjwarntext"></tool-tip>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </form>
                </div>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-primary" (click)="addsure_rwxx()">确 定</button>
              </div>
            </div>
          </div>
        </div>


      </div>
    </div>
  `,
  styles: [
    ".dzform{display: none}",
    "#myCavans{width: 1500px;height: 500px; overflow: auto;background-color: grey;position: relative;margin-bottom: 20px}",
    ".mynode{z-index: 100; position: absolute;width: 100px;height: 100px;text-align: center;line-height: 100px;border-radius: 50%; background-color: #3598dc;color: #ffffff}",
    ".line{z-index: 1; position:absolute;height:10px;background-color:blueviolet;transform-origin:left top;cursor: pointer}",
    ".line>.linebtn{position: absolute;width: 20px;height: 20px;line-height: 20px;font-size: 20px;text-align: center; top: -10px;color: #ffffff}",
    ".line .active{color: red!important;}",
    "#mapContainer{width: 70%;height: 600px;float: left}",
    ".searchform{width: 30%;height: 600px;float: left;}",
    ".searchform>#panellist{width: 100%;height:550px;overflow: auto}",
  ]
})
export class YyjhAddComponent implements OnInit, OnDestroy {
  pagetitleobj: any;
  sysBase: string;
  formgroup_yyjh: FormGroup;
  canvasHeight: number = 0; // 图的高度
  canvasHeightstr: string = "0px";
  pointerW: number = 100; // 点框的宽度
  pointerH: number = 100; // 点框的高度
  firstponterL: number = 10;
  pointerJGw: number = 200;  // 点框的左右间隔
  pointerJGh: number = 100; // 点框的上下间隔
  // 结构性的数据源, 删除节点，添加节点，改变这个对象值，然后通过drawCanvas方法，重新生成点+线【配置过任务的线，会记录起来，再getline的时候，直接返回原来的线】
  reactivePointerList: any[] = [];
  pointerList: any[] = []; // 双向绑定生成流程图的点框数据 【保存了地址信息】
  lineList: any[] = []; // 双向绑定生成流程图的线条数据【保存了任务信息】

  caozuo_pointerID: string = "";
  lastpointerList: any[] = []; // 节点添加删除变化的时候，要保持已经配置过的地址信息
  caozuo_lineID: string = "";
  lastpzlineList: any[] = []; // 节点添加删除变化的时候， 要保持已经配置过任务信息的线


  addMiddlePointer_id: string; // 添加中间点框的 主线点框id
  formgroup_addpointer: FormGroup;
  pointerIndex: number = 2; // 初始化有2个
  formgroup_pointermsg: FormGroup;
  selectDefaultField: any = {
    dzlx: "",
    rwlx: ''
  };
  table_bms: any;
  table_bzhkd: any;
  formgroup_dzform: FormGroup;
  map: any;
  placeSearch: any;
  nowselectdz: any = {
    dzlx: "",
    dzbh: "",
    dzmc: "",
    dz: "",
    dzjd: "",
    dzwd: "",
    dzzxjd: ''
  };
  formgroup_rwxx: FormGroup;
  modaltitle: string = "";
  modalflag: string = "";
  noReactiveFormField: any = {
    ksjhbh: "",
    kssjwarnflag: false,
    ksskwarntext: '开始时间不能为空',
    jssjwarnflag: false,
    jssjwarntext: "结束时间不能为空",
    yyjhsjwarnflag: "",
    yyjhsjwarntext: "计划时间段不能为空",
    sdzcache: ""
  };
  geocoder: any;

  createformgroup_yyjh(): void {
    this.formgroup_yyjh = this.fb.group({
      ysjhmcCtr: ["", [this.myValidator.myrequired("运送计划名称")]]
    });
    this.initdatetimepicker();
    this.reactivePointerList = [{
      type: "pointer",
      pointerID: "p1",
      children: []
    }, {
      type: "pointer",
      pointerID: "p2",
      children: []
    }];
    this.drawCanvas();
  }

  /**
   * 点删除或者添加（点数量变化）执行该函数
   * 1： 重新规划点的位置，和生成点的数量  【配置过信息的，要从缓存中拿到点的信息】
   * 2：根据现在点的数量，重新生成线的数量 【 线配置过信息的，要从缓存中拿到线的信息】
   *
   */
  drawCanvas(): void {
    console.log("drawCanvas", this.reactivePointerList);
    let maxchildrenNUM: number = 1;
    this.reactivePointerList.forEach((item) => {
      const children = item.children;
      if (children && children.length) {
        if (children.length > maxchildrenNUM) {
          maxchildrenNUM = children.length;
        }
      }
    });
    this.canvasHeight = maxchildrenNUM * (this.pointerH + this.pointerJGh);
    this.canvasHeightstr = `${this.canvasHeight}px`;
    this.pointerList.length = 0;
    this.lineList.length = 0;
    //######################### 处理点 ################
    this.reactivePointerList.forEach((item, index) => {
      // 处理主节点
      const pointerIDv = item.pointerID;
      const newobj = {
        type: item.type,
        pointerID: pointerIDv,
        dzxx: null,
        dzmc: "",
        dzjc: "",
        top: "0px",
        left: "0px"
      };
      if (index == 0) {
        newobj["left"] = `${this.firstponterL}px`;
      } else {
        newobj["left"] = `${this.firstponterL + this.getPreNodelen(index) * this.pointerJGw + this.getPreNodelen(index) * this.pointerW }px`;
      }
      newobj["top"] = `${this.canvasHeight / 2 - this.pointerH / 2}px`;
      this.lastpointerList.forEach((lastpointer) => {
        const lpointerid = lastpointer.pointerID;
        if (pointerIDv == lpointerid) {
          newobj.dzxx = lastpointer.dzxx;
          newobj.dzmc = lastpointer.dzmc;
          newobj.dzjc = lastpointer.dzjc;
        }
      });
      this.pointerList.push(newobj);

      // 处理主节点的子节点
      const children = item.children;
      const childrenLen = children.length;
      if (children && childrenLen) {
        children.forEach((citem, cindex) => {
          const cpointerIDv = citem.pointerID;
          const cnewobj = {
            type: citem.type,
            pointerID: cpointerIDv,
            ppointerID: pointerIDv,
            dzxx: null,
            dzmc: "",
            dzjc: "",
            top: "0px",
            left: "0px"
          }
          cnewobj["left"] = `${this.firstponterL + (this.getPreNodelen(index) + 1) * this.pointerJGw + (this.getPreNodelen(index) + 1) * this.pointerW  }px`;
          cnewobj["top"] = `${(this.canvasHeight / childrenLen - this.pointerH / 2) * cindex}px`;
          this.lastpointerList.forEach((lastpointer) => {
            const lpointerid = lastpointer.pointerID;
            if (cpointerIDv == lpointerid) {
              cnewobj.dzxx = lastpointer.dzxx;
              cnewobj.dzmc = lastpointer.dzmc;
              cnewobj.dzjc = lastpointer.dzjc;
            }
          });
          this.pointerList.push(cnewobj);
        });
      }
    });
    //########### 处理线 ###################
    setTimeout(() => {
      this.reactivePointerList.forEach((item, index) => {
        const children = item.children;
        const pointerID = item.pointerID;
        // 主线上的点和他的子节点（如果有）连线
        if (children && children.length) {
          children.forEach((citem, index) => {
            const cpointerID = citem.pointerID;
            const drawlineobj = this.getLine($(`#${pointerID}`), $(`#${cpointerID}`), false);
            this.lineList.push(drawlineobj);
          });
        }
        // 主线的上点和的  上一个节点处理
        // 上一个节点是子节点
        // 上一个节点是主节点
        if (index > 0) {
          const prepointer = this.reactivePointerList[index - 1];
          const prepointerChildren = prepointer.children;
          const prepointerID = prepointer.pointerID;
          if (prepointerChildren && prepointerChildren.length) {
            prepointerChildren.forEach((citem, index) => {
              const cpointerID = citem.pointerID;
              const drawlineobj = this.getLine($(`#${cpointerID}`), $(`#${pointerID}`), false);
              this.lineList.push(drawlineobj);
            });
          } else {
            const drawlineobj = this.getLine($(`#${prepointerID}`), $(`#${pointerID}`), true);
            this.lineList.push(drawlineobj);
          }
        }
      });
    }, 100)
  }


  getPreNodelen(index: number): number {
    let n: number = 0;
    if (index == 0) {
      n = 0;
    } else {
      n += index;
      for (let i = 0; i < index; i++) {
        const inodechildren = this.reactivePointerList[i].children;
        if (inodechildren && inodechildren.length) {
          n++;
        }
      }
    }
    return n;
  }

  /**
   * 获取线对象
   * @param startObj
   * @param endObj
   * @param {boolean} mainline--------true, startObj 是主线上的点，且和下个主线节点之间没有子节点
   * @returns {string}
   */
  getLine(startObj: any, endObj: any, mainline: boolean): any {
    const startid = startObj.attr("id");
    const endid = endObj.attr("id");

    //let html = "";
    let y_start = Math.abs(Number(startObj.css("top").replace("px", ""))) + startObj.height() / 2;
    let x_start = Math.abs(Number(startObj.css("left").replace("px", ""))) + startObj.width() / 2;
    let y_end = Math.abs(Number(endObj.css("top").replace("px", ""))) + endObj.height() / 2;
    let x_end = Math.abs(Number(endObj.css("left").replace("px", ""))) + startObj.width() / 2;
    let deg = 0;
    let length = 0;
    if (y_start == y_end) {
      // 画横线
      if (x_start > x_end) {
        const t = x_start;
        x_start = x_end;
        x_end = t
        deg = 0; // 不旋转
      }
      length = Math.abs(x_end - x_start);
    } else if (x_start == x_end) {
      // 画竖线
      deg = 90;
      if (y_start > y_end) {
        const t = y_start;
        y_start = y_end;
        y_end = t
        deg = 270;
      }
      length = Math.abs(y_end - y_start);
    } else { // 画线旋转角度
      const lx = x_end - x_start;
      const ly = y_end - y_start;
      length = Math.sqrt(lx * lx + ly * ly); //计算连线长度
      let c = 360 * Math.atan2(ly, lx) / (2 * Math.PI); //弧度值转换为角度值
      c = c <= -90 ? (360 + c) : c; //负角转换为正角
      deg = c;
    }

    // html = "<div style='top:" + y_start + "px;left:" + x_start +
    //   "px;width:" + length + "px;transform:rotate(" + deg + "deg);position:absolute;height:10px;background-color:green;transform-origin:left top;cursor: pointer'>" +
    //   "<i class='arrow-img'></i>" +
    //   "<i class='con-img'></i></div>";
    let obj: any = {
      left: `${x_start}px`,
      top: `${y_start}px`,
      width: `${length}px`,
      BpointerID: startid,  // 线开始节点id
      EpointerID: endid, //线结束节点id
      rwxx: null,
      lineID: `${startid}_${endid}`,
      ysrwwybsm: this.commservice.generateUUID(),
      transform: "rotate(" + deg + "deg)",
      linebtn_left: `${length / 2 - 40}px`,    // 配置任务信息的按钮位置
    };
    if (mainline) {
      obj["ismpointer"] = true;  // 主节点 主线上的添加中间环节的控制
      obj["linebtn1_left"] = `${length / 2}px`; // 添加中心环节的按钮位置
      obj["pointerID"] = startObj.attr("id"); // 添加中间的环节属于  这个主节点的children
    }
    // return html;
    const existLineID = `${startid}_${endid}`;
    this.lastpzlineList.forEach((item) => {
      const lineid = item.lineID;
      if (existLineID === lineid) {
        obj["rwxx"] = item.rwxx;
        obj["ysrwwybsm"] = item.ysrwwybsm;
      }
    });
    return obj;
  }

  /**
   * 添加中间节点
   * @param lineobj
   */
  addPointer(lineobj: any): void {
    const pointerID = lineobj.pointerID;
    this.addMiddlePointer_id = pointerID;
    this.formgroup_addpointer.reset();
    $("#add_pointerModal").modal({
      keyboard: true,
      backdrop: "static"
    });
  }


  createformgroup_adddPointer(): void {
    this.formgroup_addpointer = this.fb.group({
      numCtr: ["", [this.myValidator.isNumber(true)]]
    });
  }

  /**
   * 判断添加中间环节
   * 如果中间环节节点是1，则是增加主节点
   * 如果中间环节不是1，则是增加中间的子节点
   */
  addsure_pointer(): void {
    if (this.formgroup_addpointer.invalid) {
      const ctrols = this.formgroup_addpointer.controls;
      for (let path in ctrols) {
        ctrols[path].markAsDirty();
        ctrols[path].updateValueAndValidity();
      }
      return
    }
    const formgroupv = this.formgroup_addpointer.getRawValue();
    const num = formgroupv.numCtr;
    //处理
    if (num == 1) {
      // 增加主节点
      this.pointerIndex++;
      const mpointerobj = {
        type: "pointer",
        pointerID: `p${this.pointerIndex}`,
        children: []
      };
      this.reactivePointerList.push(mpointerobj);

    } else {
      // 增加子节点
      const cpointerList: any[] = [];
      for (let i = 0; i < num; i++) {
        cpointerList.push({
          type: "cpointer",
          pointerID: `${this.addMiddlePointer_id}${i + 1}`,
        })
      }
      this.reactivePointerList.forEach((item) => {
        const pointerID = item.pointerID;
        if (this.addMiddlePointer_id == pointerID) {
          item["children"] = cpointerList;
        }
      });
    }
    this.drawCanvas();
    $("#add_pointerModal").modal("hide");
  }

  /**
   * 一个元素同时绑定 单击，双击事件，不会触发双击
   * 当用户单击时，触发click。当用户在极短时间内双击时，只触发dblclic：
   * @param pointerobj
   */
  counter: number = 0;

  pointerHander(pointerobj: any): void {
    this.counter++;
    setTimeout(() => {
      if (this.counter == 1) {
        // 单击
        this.addPointerMsg(pointerobj);
      } else {
        //双击
        this.commservice.myswal("warning", "确定删除?", "", "cz", () => {
          this.removePointer(pointerobj);
        });
      }
      this.counter = 0;
    }, 300)
  }

  /**
   * 删除点框
   */
  removePointer(pointerobj: any): void {
    const removePointerID = pointerobj.pointerID;
    const removePointerType = pointerobj.type;
    if (removePointerType == "pointer") {
      this.reactivePointerList.forEach((item, mindex) => {
        const pointerID = item.pointerID;
        if (removePointerID === pointerID) {
          if (mindex != 0 && mindex != this.reactivePointerList.length - 1) {
            // 初始化中的第一个和最后一个点不允许删除
            this.reactivePointerList.splice(mindex, 1);
          }
        }
      });
    } else if (removePointerType == "cpointer") {
      const parentPointer = pointerobj.ppointerID;
      this.reactivePointerList.forEach((item, mindex) => {
        const pointerID = item.pointerID;
        if (parentPointer === pointerID) {
          const children = item.children;
          children.forEach((citem, cindex) => {
            if (citem.pointerID == removePointerID) {
              children.splice(cindex, 1);
            }
          });
        }
      });
    }
    this.drawCanvas();
  }

  /**
   * 配置节点信息（出发地/目的地）
   * @param pointerobj
   */
  addPointerMsg(pointerobj: any): void {
    this.caozuo_pointerID = pointerobj.pointerID;
    this.formgroup_pointermsg.reset({
      dzlxCtr: this.selectDefaultField.dzlx
    });
    $("#dzlxSelect").selectpicker("render");
    // 扫描点  印刷厂的表单隐藏。 显示保密室的选择表格
    this.dzlxChange();
    $("#pz_pointermsgModal").modal({
      keyboard: true,
      backdrop: "static"
    });
  }


  createformgroup_pointermsg(): void {
    this.formgroup_pointermsg = this.fb.group({
      dzlxCtr: ["", [this.myValidator.selecthas()]]
    });
    const dzlxList = [{
      DM: "bms",
      MC: "保密室"
    }, {
      DM: "bzhkd",
      MC: "标准化考点"
    }, {
      DM: "ysc",
      MC: "印刷厂"
    }, {
      DM: "smd",
      MC: "扫描点"
    }];
    $("#dzlxSelect").empty();
    let str = "";
    dzlxList.forEach((item) => {
      str += "<option value='" + item.DM + "'>" + item.MC + "</option>";
    });
    $("#dzlxSelect").append(str);
    $("#dzlxSelect").selectpicker({
      size: 5
    });
    this.selectDefaultField.dzlx = dzlxList[0].DM;
  }

  /**
   * 地址类型 change
   */
  dzlxChange(): void {
    const formgroupv = this.formgroup_pointermsg.getRawValue();
    const dzlx = formgroupv.dzlxCtr;
    // 清空当前的选择
    this.nowselectdz["dzlx"] = "";
    this.nowselectdz["dzbh"] = "";
    this.nowselectdz["dzmc"] = "";
    this.nowselectdz["dz"] = "";
    this.nowselectdz["dzjd"] = "";
    this.nowselectdz["dzwd"] = "";
    this.nowselectdz["dzzxjd"] = "";
    switch (dzlx) {
      case "bms":
        $("#dzform").hide();
        this.table_bzhkd = null;
        this.table_bms = {
          tableid: "table_bms",
          url: "bms/jcsjmkjjdyjk/sjgz/hqqbbmsxx",
          reqobj: null,
          height: 500,
          sidePagination: "client",
          pageSize: 10,
          pageList: [10, 20, 30],
          rows: "sjgzHqqbBmsList",
          columns: [{
            radio: true
          }, {
            title: "保密室名称",
            field: "bmsmc",
            cellStyle: function () {
              return {
                classes: 'td1'
              }
            }
          }, {
            title: "保密室地址",
            field: "bmsdz",
            cellStyle: function () {
              return {
                classes: 'td2'
              }
            }
          }]
        };
        if (this.sysBase == "61") {
          this.table_bms.pageSize = 50;
          this.table_bms.pageList = [50];
          this.table_bms.hiddenPageinfoLink = true;
          this.table_bms.paginationLoop = true;
          this.table_bms.paginationPreText = "<i class='fa fa-arrow-left'></i>上一页";
          this.table_bms.paginationNextText = "下一页<i class='fa fa-arrow-right'></i>";
          //this.table_bms.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 50;
        } else {
          //this.table_bms.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 50;
        }
        break;
      case "bzhkd":
        $("#dzform").hide();
        this.table_bms = null;
        this.table_bzhkd = {
          tableid: "table_bzhkd",
          url: "ksyw/sjgz/sjgzhqqbbzhkdxx",
          reqobj: null,
          height: 500,
          sidePagination: "server",
          pageSize: 10,
          pageList: [10, 20, 30],
          total: "totalRows",
          rows: "sjgzHqqbBzhkdList",
          columns: [{
            radio: true
          }, {
            title: "标准化考点名称",
            field: "bzhkdmc",
            cellStyle: function () {
              return {
                classes: 'td1'
              }
            }
          }, {
            title: "标准化考点地址",
            field: "bzhkddz",
            cellStyle: function () {
              return {
                classes: 'td2'
              }
            }
          }]
        };
        if (this.sysBase == "61") {
          this.table_bzhkd.pageSize = 50;
          this.table_bzhkd.pageList = [50];
          this.table_bzhkd.hiddenPageinfoLink = true;
          this.table_bzhkd.paginationLoop = true;
          this.table_bzhkd.paginationPreText = "<i class='fa fa-arrow-left'></i>上一页";
          this.table_bzhkd.paginationNextText = "下一页<i class='fa fa-arrow-right'></i>";
          //this.table_bzhkd.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 50;
        } else {
          //this.table_bzhkd.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 50;
        }
        break;
      case "ysc":
      case "smd":
        this.table_bms = null;
        this.table_bzhkd = null;
        this.formgroup_dzform.reset();
        $("#dzform").show();
        break;
    }
  }

  tableHander(e: any): void {
    const tableid = e.tableid;
    const caozuo = e.caozuo;
    const row = e.row;
    if (caozuo === "onCheck") {
      if (tableid == "table_bms") {
        this.nowselectdz["dzlx"] = "bms";
        this.nowselectdz["dzbh"] = row.bmsid;
        this.nowselectdz["dzmc"] = row.bmsmc;
        this.nowselectdz["dz"] = row.bmsdz;
        this.nowselectdz["dzjd"] = row.bmsjd;
        this.nowselectdz["dzwd"] = row.bmswd;
        this.nowselectdz["dzzxjd"] = row.zxjd;
      } else if (tableid == "table_bzhkd") {
        this.nowselectdz["dzlx"] = "bzhkd";
        this.nowselectdz["dzbh"] = row.bzhkdid;
        this.nowselectdz["dzmc"] = row.bzhkdmc;
        this.nowselectdz["dz"] = row.bzhkddz;
        this.nowselectdz["dzjd"] = row.bzhkdjd;
        this.nowselectdz["dzwd"] = row.bzhkdwd;
        this.nowselectdz["dzzxjd"] = row.zxjd;
      }
    }
  }

  createformgroup_dzform(): void {
    this.formgroup_dzform = this.fb.group({
      dzmcCtr: ["", [this.myValidator.myrequired("地址名称")]],
      dzCtr: ["", [this.myValidator.myrequired("地址位置")]],
      dzjdCtr: ["", [this.myValidator.myrequired("地址经度")]],
      dzwdCtr: ["", [this.myValidator.myrequired("地址纬度")]]
    });
    //处理地图选地址
  }

  /**
   * 表单地址框  显示+ 表单判断使用。
   */
  getJWD(): void {
    this.map.clearMap();
    this.placeSearch.clear();
    const dzwzv = this.formgroup_dzform.getRawValue().dzCtr;
    if (dzwzv) {
      this.noReactiveFormField.sdzcache = dzwzv;
      this.placeSearch.search(dzwzv);
      this.placeSearch.setPageIndex(1);
    } else {
      this.noReactiveFormField.sdzcache = "";
    }
    $("#mymap").modal({
      keyboard: false,
      backdrop: false
    });
  }

  /**
   * 搜搜
   */
  searchAddress(e: any): void {
    const keycode = e.keyCode;
    if (keycode == 13) {
      const sdzcachev = this.noReactiveFormField.sdzcache;
      this.placeSearch.search(sdzcachev);
    }
  }

  /**
   * 给某个点框，增加地址信息
   */
  addsure_pointerMsg(): void {
    const formgroupv = this.formgroup_pointermsg.getRawValue();
    const dzlx = formgroupv.dzlxCtr;
    if (dzlx == "bms" || dzlx == "bzhkd") {
      if (!this.nowselectdz.dzbh) {
        this.commservice.myswal("warning", "请选择地址", "", "ts", null);
        return
      }
    } else {
      // ysc  smd ----表单
      if (this.formgroup_dzform.invalid) {
        const ctrols = this.formgroup_dzform.controls;
        for (let path in ctrols) {
          ctrols[path].markAsDirty();
          ctrols[path].updateValueAndValidity();
        }
        return
      }
      const formgroupv_dzform = this.formgroup_dzform.getRawValue();
      const dzmc = this.commservice.removeSpace(true, formgroupv_dzform.dzmcCtr);
      const dz = this.commservice.removeSpace(true, formgroupv_dzform.dzCtr);
      const dzjd = formgroupv_dzform.dzjdCtr;
      const dzwd = formgroupv_dzform.dzwdCtr;
      this.nowselectdz["dzlx"] = dzlx;
      if (dzlx == "ysc") {
        this.nowselectdz["dzbh"] = "01";
      } else if (dzlx == "smd") {
        this.nowselectdz["dzbh"] = "02";
      }
      this.nowselectdz["dzmc"] = dzmc;
      this.nowselectdz["dz"] = dz;
      this.nowselectdz["dzjd"] = dzjd;
      this.nowselectdz["dzwd"] = dzwd;
      this.nowselectdz["dzzxjd"] = "";
    }

    const nowselectdz_copy = Object.assign({}, this.nowselectdz);
    this.pointerList.forEach((item) => {
      const pointerID = item.pointerID;
      if (this.caozuo_pointerID == pointerID) {
        item["dzxx"] = nowselectdz_copy;
        item["dzmc"] = nowselectdz_copy.dzmc;
        item["dzjc"] = this.commservice.showTenchart(nowselectdz_copy.dzmc, 5);
      }
    });
    this.lastpointerList = this.pointerList.slice();
    this.commservice.log("lastpointerList", this.lastpointerList);
    $("#pz_pointermsgModal").modal("hide");
  }


  /**
   * 配置任务信息
   * @param {string} actionflag
   * edite---修改配置过的信息
   * add--添加任务信息
   */
  pzrwxx(actionflag: string, lineobj: any): void {
    this.caozuo_lineID = lineobj.lineID;
    if (actionflag == "add") {
      this.modalflag = "add";
      this.modaltitle = "添加任务信息";
      this.formgroup_rwxx.reset({
        rwlxmCtr: this.selectDefaultField.rwlx
      });
      $("#rwlxSelect").selectpicker("render");
      // 时间的
      $("#kssj_rw").val("");
      $("#jssj_rw").val("");
      $(".date_btime").datetimepicker("setEndDate");
      $(".date_etime").datetimepicker("setStartDate");
    } else if (actionflag == "edite") {
      this.modalflag = "edite";
      this.modaltitle = "编辑任务信息";
      this.formgroup_rwxx.patchValue({
        rwlxmCtr: lineobj.rwxx.rwlxm,
        ysrwmcCtr: lineobj.rwxx.ysrwmc
      });
      $("#rwlxSelect").selectpicker("render");
      // 时间的
      $("#kssj_rw").val(lineobj.rwxx.rwkssj);
      $("#jssj_rw").val(lineobj.rwxx.rwjssj);
      $(".date_btime").datetimepicker("setEndDate");
      $(".date_etime").datetimepicker("setStartDate");
    }

    $("#pz_rwxxModal").modal({
      keyboard: true,
      backdrop: "static"
    });
  }

  createformgroup_rwxx(): void {
    this.formgroup_rwxx = this.fb.group({
      rwlxmCtr: ["", [this.myValidator.selecthas()]],
      ysrwmcCtr: ["", [this.myValidator.myrequired("任务名称")]],
    });
    // 字典
    this.get_zdmb();
    //时间插件的处理
    const that = this;
    $(".date_btime").datetimepicker({
      language: 'zh-CN',
      autoclose: true,
      minView: 0,
      format: "yyyy-mm-dd hh:ii:ss",
      pickerPosition: "bottom-left"
    }).on('changeDate', function (ev) {
      const selectdate = $(ev.currentTarget).find("input").val(); // yyyy-mm-dd hh:ii:ss
      //结束时间不能小于开始时间选择联动控制
      $(".date_etime").datetimepicker("setStartDate", selectdate);
    });
    $(".date_etime").datetimepicker({
      language: 'zh-CN',
      autoclose: true,
      minView: 0,
      format: "yyyy-mm-dd hh:ii:ss",
      pickerPosition: "bottom-left"
    }).on('changeDate', function (ev) {
      const selectdate = $(ev.currentTarget).find("input").val(); // yyyy-mm-dd hh:ii:ss
      //结束时间不能小于开始时间 选择联动控制
      $(".date_btime").datetimepicker("setEndDate", selectdate);
    });
  }

  get_zdmb(): void {
    const search_mbs = "jy_sjysrwlxdmb";
    this.commservice.getmbzd(search_mbs, (resp, arg) => {
        if (arg) {
          const ysrwlxArr = resp[0];
          $("#rwlxSelect").empty();
          let str: string = "<option value=''>--请选择--</option>";
          ysrwlxArr.forEach((item) => {
            str += "<option value='" + item.DM + "'>" + item.MC + "</option>";
          });
          $("#rwlxSelect").append(str);
          $("#rwlxSelect").selectpicker({
            size: 5
          });
          this.selectDefaultField.rwlx = "";
        }
      }
    );
  }

  /**
   * 判断+保存任务信息
   */
  addsure_rwxx(): void {
    if (this.formgroup_rwxx.invalid) {
      const ctrols = this.formgroup_rwxx.controls;
      for (let path in ctrols) {
        ctrols[path].markAsDirty();
        ctrols[path].updateValueAndValidity();
      }
      return
    }
    const kssjv = $("#kssj_rw").val();
    if (!kssjv) {
      this.noReactiveFormField.kssjwarnflag = true;
      return
    }
    this.noReactiveFormField.kssjwarnflag = false;
    const jssjv = $("#jssj_rw").val();
    if (!jssjv) {
      this.noReactiveFormField.jssjwarnflag = true;
      return
    }
    this.noReactiveFormField.jssjwarnflag = false;

    const formgroupv = this.formgroup_rwxx.getRawValue();
    const rwlxmv = this.commservice.removeSpace(true, formgroupv.rwlxmCtr);
    const rwlxmcv = this.commservice.removeSpace(true, $("#rwlxSelect option:selected").text());
    const ysrwmcv = this.commservice.removeSpace(true, formgroupv.ysrwmcCtr);

    this.lineList.forEach((item) => {
      const lineid = item.lineID;
      if (this.caozuo_lineID == lineid) {
        item["rwxx"] = {
          rwlxm: rwlxmv,
          rwlxmc: rwlxmcv,
          ysrwmc: ysrwmcv,
          rwkssj: kssjv,
          rwjssj: jssjv
        }
      }
    });
    this.commservice.log("处理线后的 lineList", this.lineList);
    this.lastpzlineList = this.lineList.slice();
    $("#pz_rwxxModal").modal("hide");
  }


  /**
   * 押运计划的 保存/取消
   * 0---取消
   * 1--保存
   */
  actionDone(f: number): void {
    switch (f) {
      case 0:
        this.router.navigate(["sjgzxin.jcsj/xxglx", "yyjhx"]);
        break;
      case 1:
        this.commservice.log("lineList", this.lineList);
        if (this.formgroup_yyjh.invalid) {
          const ctrols = this.formgroup_yyjh.controls;
          for (let path in ctrols) {
            ctrols[path].markAsDirty();
            ctrols[path].updateValueAndValidity();
          }
          return
        }
        const yyjh_kssj = $("#s_btimeID").val();
        const yyjh_jssj = $("#s_etimeID").val();
        if (!yyjh_kssj || !yyjh_jssj) {
          this.noReactiveFormField.yyjhsjwarnflag = true;
          return
        }
        this.noReactiveFormField.yyjhsjwarnflag = false;
        const scysrwListv: any[] = [];
        let vaild: number = 1;
        this.lineList.forEach((item) => {
          const rwxxobj = item.rwxx;
          if (!rwxxobj) {
            vaild *= 0;
          } else {
            vaild *= 1;
            const rwobj = {
              ysrwwybsm: item.ysrwwybsm,
              rwlxm: rwxxobj.rwlxm,
              rwlxmc: rwxxobj.rwlxmc,
              ysrwmc: rwxxobj.ysrwmc,
              rwkssj: rwxxobj.rwkssj,
              rwjssj: rwxxobj.rwjssj,
            };
            // 处理出发地和目的地
            const startdzID = item.BpointerID;
            const enddzID = item.EpointerID;
            const startdzObj = this.getdzobj(startdzID);
            const enddzObj = this.getdzobj(enddzID);
            if (!startdzObj || !enddzObj) {
              vaild *= 0;
            } else {
              vaild *= 1;
              rwobj["cfdbh"] = startdzObj.dzbh;
              rwobj["cfdlx"] = startdzObj.dzlx;
              rwobj["cfdmc"] = startdzObj.dzmc;
              rwobj["cfddz"] = startdzObj.dz;
              rwobj["cfdjd"] = startdzObj.dzjd;
              rwobj["cfdwd"] = startdzObj.dzwd;
              rwobj["cfdzxbh"] = startdzObj.dzzxjd;
              rwobj["mddbh"] = enddzObj.dzbh;
              rwobj["mddlx"] = enddzObj.dzlx;
              rwobj["mddmc"] = enddzObj.dzmc;
              rwobj["mdddz"] = enddzObj.dz;
              rwobj["mddjd"] = enddzObj.dzjd;
              rwobj["mddwd"] = enddzObj.dzwd;
              rwobj["mddzxbh"] = enddzObj.dzzxjd;
              // 处理 前置任务 和后置任务
              rwobj["qzrwwybsmList"] = this.getqzrwIDS(startdzID);
              rwobj["hzrwwybsmList"] = this.gethzrwIDS(enddzID);
            }
            scysrwListv.push(rwobj);
          }
        });
        if (!vaild) {
          this.commservice.myswal("warning", "信息不全", "", "ts", null);
          return
        }
        const formgroupv = this.formgroup_yyjh.getRawValue();
        const ysjhmcv = this.commservice.removeSpace(true, formgroupv.ysjhmcCtr);
        const ksjhbhv = this.noReactiveFormField.ksjhbh;
        this.commservice.blockUI({
          boxed: true,
          message: "保存中...",
          zIndex: 10051,
          overlayColor: "#67809F"
        });
        const url = "sjgz/rwjh/cjsjysjh";
        this.itservice.kwPtPost(url, {
          ysjhmc: ysjhmcv,
          jhkssj: yyjh_kssj,
          jhjssj: yyjh_jssj,
          ksjhbh: ksjhbhv,
          scysrwList: scysrwListv
        }).subscribe(resp => {
          this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
            if (arg1) {
              if (arg2) {
                this.router.navigate(["sjgzxin.jcsj/xxglx", "yyjhx"]);
              } else {
                this.commservice.myswal("warning", resp, "", "ts", null);
              }
            } else {
              this.actionDone(f);
            }
          });
        })

        break;
    }
  }

  /**
   *  根据点框的id  获取地址信息
   */
  getdzobj(pointerID: string): any {
    let dzxxobj: any = null;
    this.pointerList.forEach((item) => {
      const pointerIDv = item.pointerID;
      if (pointerID === pointerIDv) {
        dzxxobj = item.dzxx; // 可能是null---如果节点没有配置地址信息的话
      }
    });
    return dzxxobj;
  }

  /**
   * 获取任务的前置任务id 集合
   * 任务的 起点的id
   * @param {string} startPointerID
   */
  getqzrwIDS(startPointerID: string): any {
    const ids: any[] = [];
    this.lineList.forEach((item) => {
      const EpointerIDv = item.EpointerID;
      if (EpointerIDv === startPointerID) {
        ids.push(item.ysrwwybsm);
      }
    });
    return ids;
  }

  /**
   * 获取任务的后置任务id 集合
   * 任务的 终点的id
   * @param {string} endpointerID
   */
  gethzrwIDS(endpointerID: string): any {
    const ids: any[] = [];
    this.lineList.forEach((item) => {
      const BpointerIDv = item.BpointerID;
      if (BpointerIDv === endpointerID) {
        ids.push(item.ysrwwybsm);
      }
    });
    return ids;
  }

  initdatetimepicker(): void {
    $('.datetimepickerB_content').datetimepicker({
      autoclose: true,
      language: 'zh-CN',
      format: 'yyyy-mm-dd hh:ii:ss',
      pickerPosition: "bottom-left",
      minView: 0
    }).on("changeDate", function (ev) {
      const selectdate = ev.date.valueOf(); // 实际时间+ 8h
      // 结束时间不能小于开始时间,
      $(".datetimepickerE_content").datetimepicker("setStartDate", new Date(selectdate - 8 * 60 * 60 * 1000));
    });
    $('.datetimepickerE_content').datetimepicker({
      autoclose: true,
      language: 'zh-CN',
      format: 'yyyy-mm-dd hh:ii:ss',
      pickerPosition: "bottom-left",
      minView: 0
    }).on("changeDate", function (ev) {
      const selectdate = ev.date.valueOf(); // 实际时间+ 8h
      // 开始时间不能大于结束时间
      $(".datetimepickerB_content").datetimepicker("setEndDate", new Date(selectdate - 8 * 60 * 60 * 1000));
    });
  }

  //加载地图
  initmap(): void {
    const that = this;
    this.map = new AMap.Map("mapContainer", {
      resizeEnable: true,
      zoom: 8,
    });
    AMap.plugin(["AMap.PlaceSearch", "AMap.Geocoder"], function () {
      // 逆地理编码
      that.geocoder = new AMap.Geocoder({
        radius: 1000,
        extensions: "all"
      });
      that.map.addControl(that.geocoder);
      // 搜索服务
      that.placeSearch = new AMap.PlaceSearch({ //构造地点查询类
        pageSize: 8,
        pageIndex: 1,
        city: "", //兴趣点城市  可选值：城市名（中文或中文全拼）、citycode、adcode 默认值 "全国"
        map: that.map,
        panel: "panellist"
      });
      that.placeSearch.on('listElementClick', function (SelectChangeEvent) {

      });
      that.placeSearch.on('markerClick', function (SelectChangeEvent) {
        const jd = SelectChangeEvent.data.location.lng;
        const wd = SelectChangeEvent.data.location.lat;
        that.formgroup_dzform.patchValue({
          dzjdCtr: jd,
          dzwdCtr: wd
        });
        // 根据经纬度 获取到地址，填充 formgroup_dzform 表单
        that.getAddresss([jd, wd], (resp) => {
          const dzv = resp.regeocode.formattedAddress;
          that.formgroup_dzform.patchValue({
            dzCtr: dzv
          });
          $("#mymap").modal("hide");
        });
      });
    });
    this.map.on("click", (e) => {
      const clickLngLat = e.lnglat;
      const jdv = clickLngLat.getLng();
      const wdv = clickLngLat.getLat();
      this.formgroup_dzform.patchValue({
        dzjdCtr: jdv,
        dzwdCtr: wdv
      });
      // 根据经纬度 获取到地址，填充 formgroup_dzform 表单
      this.getAddresss([jdv, wdv], (resp) => {
        const dzv = resp.regeocode.formattedAddress;
        this.formgroup_dzform.patchValue({
          dzCtr: dzv
        });
        $("#mymap").modal("hide");
      });
    });
  }

  getAddresss(lnglatXY: any, callback: Function): void {
    this.geocoder.getAddress(lnglatXY, function (status, result) {
      if (status === 'complete' && result.info === 'OK') {
        callback(result);
      }
    });
  }

  constructor(private fb: FormBuilder,
              private localStorageService: LocalStorageService,
              private myValidator: MyValidator,
              private commservice: CommService,
              private itservice: MyhttpService,
              private router: Router) {

  }

  ngOnInit() {
    this.pagetitleobj = sjgzxinModuledatas.yyjh;
    this.noReactiveFormField.ksjhbh = this.localStorageService.get("hksjh");
    this.commservice.getSysmsg2((resp) => {
      this.sysBase = resp.sysBase;
    });
    this.createformgroup_yyjh();
    this.createformgroup_adddPointer();
    this.createformgroup_pointermsg();
    this.createformgroup_dzform();
    this.createformgroup_rwxx();
    this.initmap();
  }

  ngOnDestroy() {

  }

}
